package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/yuewen/config"
	"net/http"
	"net/url"
)

type BookGetNovelInfoApiService service

type BookGetNovelInfoRequest struct {
	ctx        context.Context
	ApiService *BookGetNovelInfoApiService
	bookId     *uint64
	appFlag    *string
}

type BookGetNovelInfoResponse struct {
	Code    *int64     `json:"code,omitempty"`
	Message *string    `json:"message,omitempty"`
	Data    *NovelInfo `json:"data,omitempty"`
}

type NovelInfo struct {
	BookId        *string `json:"book_id,omitempty"`
	BookName      *string `json:"book_name,omitempty"`
	AuthorFlag    *string `json:"author_name,omitempty"`
	AllWords      *uint64 `json:"all_words,omitempty"`
	UpdateTime    *string `json:"update_time,omitempty"`
	ChargeChapter *uint64 `json:"charge_chapter,omitempty"`
}

func (r *BookGetNovelInfoRequest) BookId(bookId uint64) *BookGetNovelInfoRequest {
	r.bookId = &bookId
	return r
}

func (r *BookGetNovelInfoRequest) AppFlag(appFlag string) *BookGetNovelInfoRequest {
	r.appFlag = &appFlag
	return r
}

func (r *BookGetNovelInfoRequest) Execute() (*BookGetNovelInfoResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *BookGetNovelInfoRequest) ApiSecret(ApiSecret string) *BookGetNovelInfoRequest {
	r.ctx = context.WithValue(r.ctx, config.ApiSecret, ApiSecret)
	return r
}

func (r *BookGetNovelInfoRequest) Email(Email string) *BookGetNovelInfoRequest {
	r.ctx = context.WithValue(r.ctx, config.Email, Email)
	return r
}

func (r *BookGetNovelInfoRequest) WithLog(enable bool) *BookGetNovelInfoRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *BookGetNovelInfoApiService) Get(ctx context.Context) *BookGetNovelInfoRequest {
	return &BookGetNovelInfoRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *BookGetNovelInfoApiService) getExecute(r *BookGetNovelInfoRequest) (*BookGetNovelInfoResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/" + cfg.Prefix + "/Book/GetNovelInfo"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *BookGetNovelInfoResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasAppFlag(r.appFlag); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	if ok, GenericOpenAPIError := hasReqParam(r.bookId, "BookId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	localVarQueryParams.Add("book_id", toString(r.bookId))
	localVarQueryParams.Add("appflag", *r.appFlag)

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
